package com.hwadee.property.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfig {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hwadee.property.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket fileApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("工具管理") // 用户管理分组
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hwadee.property.controller.util"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket peopleApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("账户管理") // 用户管理分组
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hwadee.property.controller.people"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket parkingApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("停车管理") // 停车管理分组
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hwadee.property.controller.parking"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket infoApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("消息管理") // 信息相关分组
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hwadee.property.controller.info"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket houseApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("住宅管理") // 住宅相关分组
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hwadee.property.controller.house"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket permissionApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("权限管理") // 权限相关分组
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hwadee.property.controller.permission"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket chargeApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("收费管理") // 收费相关分组
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hwadee.property.controller.charge"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("物业管理系统API文档")
                .description("API 文档描述")
                .version("1.0")
                .contact(new Contact("LX134340", "https://gitee.com/yue-huang-jinling", "1876126165@qq.com"))
                .build();
    }

}
